package ch11_多线程与并发;

public class WebSiteCounter {
	public static void main(String[] args) throws InterruptedException{
		WebSite site = new WebSite();
		new Thread(site,"用户1").start();
		new Thread(site,"用户2").start();
		new Thread(site,"用户3").start();
		Thread.sleep(100);
	}
}
class WebSite implements Runnable{
	int count = 0;
	@Override
	public synchronized void run() {	//3加了关键字
//		1System.out.println(Thread.currentThread().getName()+":第"+(++count)+"位访问者");
//		2synchronized(this) {
//			System.out.println(Thread.currentThread().getName()+":第"+(++count)+"位访问者");
//		}
		System.out.println(Thread.currentThread().getName()+":第"+(++count)+"位访问者");
	}

}
